using System;
using System.Collections.Generic;
using CMS.Core.DataInterfaces;
using CMS.Core.Domain;

namespace CMS.Data
{
    public class BaiVietTheLoaiDao : AbstractNHibernateDao<BaiVietTheLoai, System.Int32>, IBaiVietTheLoaiDao
    {
        #region Create Instance
        private static BaiVietTheLoaiDao instance = null;
        public static BaiVietTheLoaiDao Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new BaiVietTheLoaiDao();
                }
                return instance;
            }
        }
        #endregion

        #region IBaiVietTheLoaiDao Members

        public byte GetMaxSTT(int maTheLoaiCha)
        {
            byte result = 1;
            try
            {
                Object obj = null;
                String strSQL = @"Select Max(tl.ThuTu) from BaiVietTheLoai tl Where tl.TheLoaiCha.ID = :THELOAILOOKUP";
                obj = NHibernateSessionManager.Instance.GetSession().CreateQuery(strSQL)
                    .SetParameter("THELOAILOOKUP", maTheLoaiCha)
                    .UniqueResult();
                if (obj != null)
                {
                    result = Convert.ToByte(obj);
                    result += 1;
                }
                return result;
            }
            catch (Exception ex)
            {
                System.Console.Write(ex);
                return result;
            }
        }
        #endregion
    }
}
